package com.santu.edu.supporter.biz.pay.controller;

import com.santu.edu.supporter.biz.pay.service.WxOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;

/**
 * 微信 - 用户订单管理
 */
@RestController
@RequestMapping("/wx/order")
@Validated
@RequiredArgsConstructor
public class WxOrderController {

    private final WxOrderService wxOrderService;


    /**
     * 订单支付后回调
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("wxOrderCallBack")
    public Boolean wxOrderCallBack(HttpServletRequest request, HttpServletResponse response) {
        return wxOrderService.wxOrderCallBack(request, response);
    }

    /**
     * 订单退款
     *
     * @param orderId
     * @return
     */
    @GetMapping("orderRefund")
    public Boolean orderRefund(@NotBlank(message = "orderId不能为空") String orderId) {
        return wxOrderService.orderRefund(orderId);
    }

    /**
     * 微信退款回调接口
     *
     * @param request
     * @param response
     * @return
     */
    @PostMapping("refundWechatCallback")
    public Boolean refundWechatCallback(HttpServletRequest request, HttpServletResponse response) {
        return wxOrderService.refundWechatCallback(request, response);
    }

}
